import 'package:any_reader/public.dart';

class CustomDialog extends StatefulWidget {
  final String title;
  final String message;
  final String confirmButtonText;
  final String cancelButtonText;
  final bool showConfirmButton;
  final bool showCancelButton;
  final void Function() onClose;
  final void Function() confirm;
  final void Function() cancel;
  final TextAlign messageAlign;
  final Color bgColor;
  final Color txtColor;
  final double fontSize;
  CustomDialog({
    @required this.title,
    this.message,
    this.confirmButtonText = "确定",
    this.cancelButtonText = "取消",
    this.messageAlign,
    this.showCancelButton = true,
    this.showConfirmButton = true,
    this.confirm,
    this.cancel,
    this.onClose,
    this.bgColor,
    this.txtColor,
    this.fontSize,
  });

  @override
  _CustomDialog createState() => _CustomDialog();
}

class _CustomDialog extends State<CustomDialog> {
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Material(
      color: Color.fromARGB(0, 0, 0, 0),
      child: Container(
        width: ScreenUtil().setWidth(750),
        height: ScreenUtil().setHeight(1334),
        child: GestureDetector(
          child: Center(
            child: ClipRRect(
              borderRadius: BorderRadius.circular(30),
              child: Container(
                color: widget.bgColor,
                width: ScreenUtil().setWidth(750 * 0.8),
                height: ScreenUtil().setWidth(400),
                child: Stack(
                  children: <Widget>[
                    Container(
                      height: ScreenUtil().setWidth(300),
                      width: ScreenUtil().setWidth(750 * 0.8),
                      margin: EdgeInsets.fromLTRB(
                        ScreenUtil().setWidth(50),
                        ScreenUtil().setHeight(0),
                        ScreenUtil().setWidth(50),
                        ScreenUtil().setHeight(0),
                      ),
                      alignment: Alignment.center,
                      child: Text(
                        widget.title,
                        style: TextStyle(
                          fontFamily: "dengxian",
                          height: 1.5,
                          letterSpacing: 2,
                          fontSize: widget.fontSize ?? ScreenUtil().setSp(30),
                          fontWeight: FontWeight.w900,
                          color: widget.txtColor,
                        ),
                      ),
                    ),
                    Positioned(
                      bottom: 0,
                      left: 0,
                      width: ScreenUtil().setWidth(750 * 0.8),
                      height: ScreenUtil().setHeight(100),
                      child: Row(
                        children: <Widget>[
                          () {
                            if (widget.showCancelButton) {
                              return Expanded(
                                flex: 1,
                                child: Material(
                                  child: Ink(
                                    color: widget.bgColor,
                                    child: InkWell(
                                      highlightColor:
                                          widget.bgColor.withRed(50),
                                      splashColor: widget.bgColor.withRed(50),
                                      onTap: widget.cancel ??
                                          () {
                                            Navigator.pop(context);
                                          },
                                      child: Container(
                                        decoration: BoxDecoration(
                                            border: Border.all(
                                                color: Color(0xFFebedf0)
                                                    .withOpacity(0.1),
                                                width: 0.1)),
                                        alignment: Alignment.center,
                                        height: ScreenUtil().setHeight(100),
                                        child: Text(
                                          widget.cancelButtonText,
                                          style: TextStyle(
                                            fontSize: ScreenUtil().setSp(26),
                                            color: widget.txtColor,
                                          ),
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                              );
                            } else {
                              return Container();
                            }
                          }(),
                          Expanded(
                            flex: 1,
                            child: Material(
                              child: Ink(
                                color: widget.bgColor,
                                child: InkWell(
                                  highlightColor: widget.bgColor.withRed(50),
                                  splashColor: widget.bgColor.withRed(50),
                                  onTap: widget.confirm ??
                                      () {
                                        Navigator.pop(context);
                                      },
                                  child: Container(
                                    decoration: BoxDecoration(
                                        border: Border.all(
                                            color: Color(0xFFebedf0)
                                                .withOpacity(0.1),
                                            width: 0.1)),
                                    alignment: Alignment.center,
                                    height: ScreenUtil().setHeight(100),
                                    child: Text(
                                      widget.confirmButtonText,
                                      style: TextStyle(
                                          fontSize: ScreenUtil().setSp(26),
                                          color: Colors.red),
                                    ),
                                  ),
                                ),
                              ),
                            ),
                          )
                        ],
                      ),
                    )
                  ],
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}
